package com.ruoyi.machine.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.machine.domain.Dto.EExpressBoxesDto;
import com.ruoyi.machine.domain.EExpressBoxes;
import com.ruoyi.machine.domain.UseCountMap;
import com.ruoyi.machine.domain.Vo.EExpressBoxesVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.ArrayList;
import java.util.List;

@Mapper
public interface EExpressBoxesMapper extends BaseMapper<EExpressBoxes> {

    @Select("select is_status from e_express_boxes where machine_id = #{id}")
    List<EExpressBoxes> findBoxesById(Long id);

    List<EExpressBoxesDto> findBoxList(EExpressBoxesVo vo);

    @Select("<script>" +
            "SELECT machine_id AS id, COUNT(*) AS useCount " +
            "FROM e_express_boxes " +
            "WHERE machine_id IN " +
            "<foreach item='item' index='index' collection='arrayList' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "AND is_status = 1 " +
            "GROUP BY machine_id" +
            "</script>")
    List<UseCountMap> selectBoxes(ArrayList<Integer> arrayList);

    EExpressBoxesDto findBoxById(Integer id);

    void insertBatch(List<EExpressBoxes> boxes);

    void updateBox(EExpressBoxes boxes);
}
